package com.ygp.monitor;

import java.util.concurrent.locks.ReentrantLock;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2021/09/14 <br>
 */
public class ReentrantLockExample {
    int a = 0;
    ReentrantLock lock = new ReentrantLock(true);

    public void writer() {
        lock.lock();
        try {
            a++;
        } finally {
            lock.unlock();
        }
    }

    public void reader() {
        lock.lock();
        try {
            int i = a;
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        new ReentrantLockExample().writer();
    }
}
